package zhuanyeshixi2.basic.vo;

import java.util.List;

/**
 * 用户值对象 (Value Object)
 * 用于前端和后端之间的数据传输
 */
public class UserVo {
    private Integer userId;
    private String username;
    private String password;
    private String realName;
    private String email;
    private String phone;
    private List<Integer> roleIds;  // 用于接收角色ID列表
    private List<String> roles;     // 用于返回角色名称列表

    // 默认构造方法
    public UserVo() {
    }

    // 带参数的构造方法
    public UserVo(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public UserVo(String username, String password, String email) {
        this.username = username;
        this.password = password;
        this.email = email;
    }

    // Getter 和 Setter 方法
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public List<Integer> getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(List<Integer> roleIds) {
        this.roleIds = roleIds;
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }

    @Override
    public String toString() {
        return "UserVo{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + (password != null ? "***" : "null") + '\'' +
                ", realName='" + realName + '\'' +
                ", email='" + email + '\'' +
                ", phone='" + phone + '\'' +
                ", roleIds=" + roleIds +
                ", roles=" + roles +
                '}';
    }

    // 便捷方法
    public boolean hasRole(String roleName) {
        return roles != null && roles.contains(roleName);
    }

    public boolean isAdmin() {
        return hasRole("admin") || hasRole("管理员");
    }
}